<?php
use Medoo\Medoo;

class Singleton
{

    static private $db;
    static private $redis;

    //防止使用new直接创建对象

    private function __construct(){}

    //防止使用clone克隆对象

    private function __clone(){}

    static public function getDb()
    {
        if (!self::$db instanceof Medoo) {
            $arrConfig = Yaf_Application::app()->getConfig();
            $mysql = $arrConfig['mysql']->toArray();
            if(isset($mysql['logging']) && $mysql['logging']){
                $mysql['logging'] = true;
            }    
            $mysql['error'] = PDO::ERRMODE_EXCEPTION;        
            self::$db = new Medoo($mysql);
        }
        return self::$db;
    }

    static public function getRedis()
    {
        if (!self::$redis instanceof Redis) {
            $arrConfig = Yaf_Application::app()->getConfig();
            self::$redis = new Redis();
            self::$redis->connect($arrConfig['redis']->server,$arrConfig['redis']->port);
        }
        return self::$redis;
    }

    

}